<?php

ini_set('memory_limit','16M');

require_once( '/home/cyberpower678/Peachy/Init.php' );

$site = Peachy::newWiki( "cyberbot i" );

$site->set_runpage("User:Cyberbot I/Run/AFDREM");

$template = initPage( "Template:REMOVE THIS TEMPLATE WHEN CLOSING THIS AfD" );
$p = array();

$pages = $template->embeddedin( 4 );
foreach( $pages as $page ) {
        echo $page."\n";
        if( substr($page,0,36) == 'Wikipedia:Articles for deletion/Log/' ) continue;
        if( substr($page,0,32) != 'Wikipedia:Articles for deletion/' ) continue;
        echo $page."\n";
        $p[] = $page;
}
/*while( isset($pages[499]) ) {
        $pages = $site->get_embeddedin($template,'500',$continue,4);
        foreach( $pages as $page ) {
                echo $page."\n";
                if( substr($page,0,36) == 'Wikipedia:Articles for deletion/Log/' ) continue;
                if( substr($page,0,32) != 'Wikipedia:Articles for deletion/' ) continue;
                echo $page."\n";
                $p[] = $page;
        }
}*/

$c = 1;

foreach ($p as $pg) {
//      if( $c > 10 ) break;
        $page = initPage( $pg );
        $text = $page->get_text();
        
        if( preg_match('/\<!--Template:Afd top/Si', $text) ) {
                $newtext = preg_replace('/\{\{REMOVE THIS TEMPLATE WHEN CLOSING THIS AfD(.*)\}\}/i', '', $text);
                //$diff = getTextDiff('unified', $text, $newtext);
                
                if( $page->edit( $newtext, "Removing categorization template from closed AFD", true ) ) $c++;
        }
}

/*
try {
        $page->put($newtext,"Dating maintenance tags (bot edit)",true);
} catch (PillarException $e) {
        continue;
}
*/

?>

